package com.yanqu.road.entity.activity.washe.config;

import com.yanqu.road.entity.FieldTypeAnnotation;
import com.yanqu.road.utils.LocalDateTimeHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

@FieldTypeAnnotation(tableName = "t_n_washepvp_seasontime")
public class WasheSeasonConfig {

    @FieldTypeAnnotation(desc = "活动ID", select = true)
    private int activityId;
    @FieldTypeAnnotation(desc = "赛季ID")
    private int seasonId;
    @FieldTypeAnnotation(desc = "开始展示时间")
    private String beginShowTimeStr;
    @FieldTypeAnnotation(desc = "开始时间")
    private String beginTimeStr;
    @FieldTypeAnnotation(desc = "结束时间")
    private String endTimeStr;
    @FieldTypeAnnotation(desc = "结束展示时间")
    private String endShowTimeStr;

    @FieldTypeAnnotation(desc = "积分赛开始时间")
    private String integralBeginTimeStr;
    @FieldTypeAnnotation(desc = "积分赛结束时间")
    private String integralEndTimeStr;
    @FieldTypeAnnotation(desc = "巅峰赛开始时间")
    private String peakednessBeginTimeStr;
    @FieldTypeAnnotation(desc = "巅峰赛结束时间")
    private String peakednessEndTimeStr;

    @FieldTypeAnnotation(desc = "锦标赛开关, 0:不开积分赛不开巅峰赛, 1:开积分赛开巅峰赛,2:开积分赛不开巅峰赛")
    private int jinBiaoSwitch;

    @FieldTypeAnnotation(desc = "赛季任务道具ID")
    private int taskItemId;
    @FieldTypeAnnotation(desc = "赛季主题")
    private String theme;
    @FieldTypeAnnotation(desc = "赛季描述")
    private String themeDesc = "";

    // 转时间戳方便用
    private long beginShowTime;
    private long beginTime;
    private long endTime;
    private long endShowTime;

    private long integralBeginTime;

    private long integralEndTime;

    private long peakednessBeginTime;

    private long peakednessEndTime;

    // ===============================

    public boolean isJiFenOpen() {
        return jinBiaoSwitch == 1 || jinBiaoSwitch == 2;
    }

    public boolean isDianFengOpen() {
        return jinBiaoSwitch == 1;
    }

    // ===============================

    public void init(int channelActivityTimeZone) {
        try {

            SimpleDateFormat format = new SimpleDateFormat("yyyy=MM=dd=HH=mm");
            format.setTimeZone(TimeZone.getDefault());

            Date beginShowTime = format.parse(beginShowTimeStr);
            setBeginShowTime(LocalDateTimeHelper.convertTimeZone(beginShowTime.getTime(), channelActivityTimeZone, false));

            Date begin = format.parse(beginTimeStr);
            setBeginTime(LocalDateTimeHelper.convertTimeZone(begin.getTime(), channelActivityTimeZone, false));

            Date end = format.parse(endTimeStr);
            setEndTime(LocalDateTimeHelper.convertTimeZone(end.getTime(), channelActivityTimeZone, false));

            Date endShowTime = format.parse(endShowTimeStr);
            setEndShowTime(LocalDateTimeHelper.convertTimeZone(endShowTime.getTime(), channelActivityTimeZone, false));

            if (!StringUtils.isNullOrEmpty(integralBeginTimeStr)) {
                Date integralBeginTime = format.parse(integralBeginTimeStr);
                setIntegralBeginTime(LocalDateTimeHelper.convertTimeZone(integralBeginTime.getTime(), channelActivityTimeZone, false));
            }

            if (!StringUtils.isNullOrEmpty(integralEndTimeStr)) {
                Date integralEndTime = format.parse(integralEndTimeStr);
                setIntegralEndTime(LocalDateTimeHelper.convertTimeZone(integralEndTime.getTime(), channelActivityTimeZone, false));
            }

            if (!StringUtils.isNullOrEmpty(peakednessBeginTimeStr)) {
                Date peakednessBeginTime = format.parse(peakednessBeginTimeStr);
                setPeakednessBeginTime(LocalDateTimeHelper.convertTimeZone(peakednessBeginTime.getTime(), channelActivityTimeZone, false));
            }

            if (!StringUtils.isNullOrEmpty(peakednessEndTimeStr)) {
                Date peakednessEndTime = format.parse(peakednessEndTimeStr);
                setPeakednessEndTime(LocalDateTimeHelper.convertTimeZone(peakednessEndTime.getTime(), channelActivityTimeZone, false));
            }

        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }

    // ===============================

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        this.activityId = activityId;
    }

    public int getSeasonId() {
        return seasonId;
    }

    public void setSeasonId(int seasonId) {
        this.seasonId = seasonId;
    }

    public String getBeginTimeStr() {
        return beginTimeStr;
    }

    public void setBeginTimeStr(String beginTimeStr) {
        this.beginTimeStr = beginTimeStr;
    }

    public String getEndTimeStr() {
        return endTimeStr;
    }

    public void setEndTimeStr(String endTimeStr) {
        this.endTimeStr = endTimeStr;
    }

    public long getBeginTime() {
        return beginTime;
    }

    public void setBeginTime(long beginTime) {
        this.beginTime = beginTime;
    }

    public long getEndTime() {
        return endTime;
    }

    public void setEndTime(long endTime) {
        this.endTime = endTime;
    }

    public int getTaskItemId() {
        return taskItemId;
    }

    public void setTaskItemId(int taskItemId) {
        this.taskItemId = taskItemId;
    }

    public String getBeginShowTimeStr() {
        return beginShowTimeStr;
    }

    public void setBeginShowTimeStr(String beginShowTimeStr) {
        this.beginShowTimeStr = beginShowTimeStr;
    }

    public String getEndShowTimeStr() {
        return endShowTimeStr;
    }

    public void setEndShowTimeStr(String endShowTimeStr) {
        this.endShowTimeStr = endShowTimeStr;
    }

    public long getBeginShowTime() {
        return beginShowTime;
    }

    public void setBeginShowTime(long beginShowTime) {
        this.beginShowTime = beginShowTime;
    }

    public long getEndShowTime() {
        return endShowTime;
    }

    public void setEndShowTime(long endShowTime) {
        this.endShowTime = endShowTime;
    }

    public String getIntegralBeginTimeStr() {
        return integralBeginTimeStr;
    }

    public void setIntegralBeginTimeStr(String integralBeginTimeStr) {
        this.integralBeginTimeStr = integralBeginTimeStr;
    }

    public String getIntegralEndTimeStr() {
        return integralEndTimeStr;
    }

    public void setIntegralEndTimeStr(String integralEndTimeStr) {
        this.integralEndTimeStr = integralEndTimeStr;
    }

    public String getPeakednessBeginTimeStr() {
        return peakednessBeginTimeStr;
    }

    public void setPeakednessBeginTimeStr(String peakednessBeginTimeStr) {
        this.peakednessBeginTimeStr = peakednessBeginTimeStr;
    }

    public String getPeakednessEndTimeStr() {
        return peakednessEndTimeStr;
    }

    public void setPeakednessEndTimeStr(String peakednessEndTimeStr) {
        this.peakednessEndTimeStr = peakednessEndTimeStr;
    }

    public long getIntegralBeginTime() {
        return integralBeginTime;
    }

    public void setIntegralBeginTime(long integralBeginTime) {
        this.integralBeginTime = integralBeginTime;
    }

    public long getIntegralEndTime() {
        return integralEndTime;
    }

    public void setIntegralEndTime(long integralEndTime) {
        this.integralEndTime = integralEndTime;
    }

    public long getPeakednessBeginTime() {
        return peakednessBeginTime;
    }

    public void setPeakednessBeginTime(long peakednessBeginTime) {
        this.peakednessBeginTime = peakednessBeginTime;
    }

    public long getPeakednessEndTime() {
        return peakednessEndTime;
    }

    public void setPeakednessEndTime(long peakednessEndTime) {
        this.peakednessEndTime = peakednessEndTime;
    }

    public int getJinBiaoSwitch() {
        return jinBiaoSwitch;
    }

    public void setJinBiaoSwitch(int jinBiaoSwitch) {
        this.jinBiaoSwitch = jinBiaoSwitch;
    }

    public String getTheme() {
        return theme;
    }

    public void setTheme(String theme) {
        this.theme = theme;
    }

    public String getThemeDesc() {
        return themeDesc;
    }

    public void setThemeDesc(String themeDesc) {
        if (themeDesc == null) {
            return;
        }
        this.themeDesc = themeDesc;
    }
}
